import { lazy, Suspense } from 'react'

function LazyLoad(url) {
    let message = ''
    const Module = lazy(() => {
        return new Promise((resolve,reject) => {
            import('../components' + url)
            .then(res => resolve(res))
            .catch(err => {
                import('../components/ErrorPage')
                message = JSON.parse(err)
            })
        })
    })
    return <Suspense fallback={<h2>加载中......</h2>}>
        <Module message={message}></Module>
    </Suspense>
}

export default LazyLoad